<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function response($code, $msg, $data)
    {
        $res = [];
        $res['code'] = $code;
        $res['msg'] = $msg;
        $res['data'] = $data;
        return response()->json($res);
    }

    public function exceptionResponse(\Exception $exception)
    {
        $res = [];
        $res['code'] = $exception->getCode();
        $res['file'] = $exception->getFile();
        $res['line'] = $exception->getLine();
        $res['message'] = $exception->getMessage();
        $res['previous'] = $exception->getPrevious();
        $res['trace'] = $exception->getTrace();
        return $this->response(0, 'Server internal error', $res);
    }
}
